#include "widget.h"
#include "ui_widget.h"

#include <QDebug>
#include <QButtonGroup>
#include <QHash>
#include <QString>

static QHash<int, QString> hash;

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QButtonGroup* group1 = new QButtonGroup(this);
    QButtonGroup* group2 = new QButtonGroup(this);
    QButtonGroup* group3 = new QButtonGroup(this);

    group1->addButton(ui->radioButton);
    group1->addButton(ui->radioButton_2);
    group1->addButton(ui->radioButton_3);

    group2->addButton(ui->radioButton_4);
    group2->addButton(ui->radioButton_5);
    group2->addButton(ui->radioButton_6);

    group3->addButton(ui->radioButton_7);
    group3->addButton(ui->radioButton_8);
    group3->addButton(ui->radioButton_9);

    hash[0] = ui->radioButton->text();
    hash[1] = ui->radioButton_2->text();
    hash[2] = ui->radioButton_3->text();
    hash[3] = ui->radioButton_4->text();
    hash[4] = ui->radioButton_5->text();
    hash[5] = ui->radioButton_6->text();
    hash[6] = ui->radioButton_7->text();
    hash[7] = ui->radioButton_8->text();
    hash[8] = ui->radioButton_9->text();
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    QString s;
    int a[9] = {
        ui->radioButton->isChecked(),
        ui->radioButton_2->isChecked(),
        ui->radioButton_3->isChecked(),
        ui->radioButton_4->isChecked(),
        ui->radioButton_5->isChecked(),
        ui->radioButton_6->isChecked(),
        ui->radioButton_7->isChecked(),
        ui->radioButton_8->isChecked(),
        ui->radioButton_9->isChecked()
    };
    int sum = 0;
    for(int i = 0; i < 9; i++)
    {
        sum += a[i];
        if(a[i] == 1)
            s += hash[i] + "x1\n";
    }
    if(sum != 3)
    {
        ui->label_result->setText("请选择你要吃的食物");
        return;
    }
    ui->label_result->setText("你选择的套餐为:\n" + s);

}

